package com.syni.mdd.sjb.common.datatreaure.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.syni.mdd.sjb.common.component.utils.common.utils.AppConfig;
import com.syni.mdd.sjb.common.component.utils.common.utils.RestTemplateUtils;
import com.syni.mdd.sjb.common.datatreaure.service.MinAppService;
import com.syni.mdd.sjb.common.datatreaure.constants.ResultCode;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 店铺表 服务实现类
 * </p>
 *
 * @author lcc
 * @since 2020-05-06
 */
@Service
@Log4j2
public class MinAppServiceImpl implements MinAppService {
    @Override
    public boolean checkDxshMinAppToken(String userToken) {
        String postUrl = AppConfig.getProperty("wxMinAppAddress") + "/DSP_WX_MINAPP/minApp/checkCommonUserToken";
        Map<String,Object> paramsMap = new HashMap<>();
        paramsMap.put("userToken",userToken);
        try {
            String responseBody = RestTemplateUtils.postForEntityForJson(postUrl,paramsMap);
            JSONObject responseJson = JSON.parseObject(responseBody);
            if(responseJson.containsKey("status") && responseJson.getString("status").equals(ResultCode.CODE_NORMAL)){
                return true;
            }
        }catch (Exception e){
            log.error(e.getMessage(),e);
        }
        return false;
    }
}
